import {editSpecsRows} from "@/views/modals/specsRows.config";

export const monthsList = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
export const cqList = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]

export const rppSep = {
   "ROW": ["349", "149"],
   "NA": ["999", "399", "149"],
   "JP": [],
   "Xiaomi": ["799", "299", "129"],
   "Samsung": ["799", "299", "129"],
   "Oppo": ["799", "299", "129"],
   "Vivo": ["799", "299", "129"],
   "Realme": ["799", "299", "129"],
   "Honor": ["799", "299", "129"]
}

export const curSymb = {
   ROW: "€",
   NA: "$",
   JP: "¥",
   Xiaomi: "€",
   Samsung: "€",
   Oppo: "€",
   Vivo: "€",
   Realme: "€",
   Honor: "€"
}

export const leftPriceList = {
   ROW: ["99", "129", "149", "179", "199", "249", "299", "349", "399", "499", "599", "699", "799", "899", "999"],
   NA: ["99", "149", "179", "199", "249", "299", "399", "449", "499", "699", "799", "899", "999", "999+"],
   JP: ["28800", "32800", "44800", "54800", "68800", "142800"],
   Xiaomi: ["99", "129", "149", "179", "199", "249", "299", "349", "399", "499", "599", "699", "799", "999"],
   Samsung: ["99", "129", "149", "179", "199", "249", "299", "349", "399", "499", "599", "699", "799", "999"],
   Oppo: ["99", "129", "149", "179", "199", "249", "299", "349", "399", "499", "599", "699", "799", "999"],
   Vivo: ["99", "129", "149", "179", "199", "249", "299", "349", "399", "499", "599", "699", "799", "999"],
   Realme: ["99", "129", "149", "179", "199", "249", "299", "349", "399", "499", "599", "699", "799", "999"],
   Honor: ["99", "129", "149", "179", "199", "249", "299", "349", "399", "499", "599", "699", "799", "999"],
}

export const catTypes = ["E", "G", "Premium", "Razr"]
export const devTypes = ["", "OT", "TN", "HQ", "WT", "LC", "IH"]
export const swDevTypes = ["", "ODM", "IH"]
export const netTypes = ["", "4G", "5G"]
export const b2bTypes = ["N", "Y"]

export const defColors = ["BlueViolet", "Crimson", "Coral", "DeepPink", "DarkGreen"];

export const getDateSplit = (date) => {
   date = date && date instanceof Date ? new Date(date) : new Date()
   return { year: date.getFullYear(), month: date.getMonth() }
}

export const getGeoType = () => {
   return document.querySelector('.left-price-top-type').textContent
}

export const getPageYear = () => {
   return document.querySelector('.row-list-top-header').getAttribute('data-year')
}

// 鼠标悬浮产品进行展示
export const mouseTopData = [
   { label: 'Network', row: 'network',},
   { label: 'RF', row: 'specs.rf',},
   { label: 'OK2Ship', row: 'ok2Ship', type: 'date'},
   { label: 'Dimension', row: ['dimension.d_x', 'dimension.d_y', 'dimension.d_z'], unit: 'mm'},
   { label: 'Bezel', row: 'dimension.bezel', unit: 'mm'},
   { label: 'Head', row: 'dimension.head', unit: 'mm'},
   { label: 'Chin', row: 'dimension.chin', unit: 'mm'},
   { label: 'Weight', row: 'dimension.weight', unit: 'g'},
   { label: 'CMF', row: 'specs.me_cmf'},
   { label: 'Display#1', row: 'specs.display1'},
   { label: 'Display#2', row: 'specs.display2'},
   { label: 'Platform', row: 'specs.chipset'},
   { label: 'Memory', row: 'specs.memory'},
   { label: 'Cam #1', row: 'specs.cam1'},
   { label: 'Cam #2', row: 'specs.cam2',},
   { label: 'Cam #3', row: 'specs.cam3',},
   { label: 'Cam #4', row: 'specs.cam4',},
   { label: 'Cam #5', row: 'specs.cam5',},
   { label: 'F. Cam#1', row: 'specs.fCam1'},
   { label: 'F. Cam#2', row: 'specs.fCam2'},
   // { label: 'Selfie Camera', row: 'BY'},
   { label: 'Sound', row: 'specs.audio'},
   { label: 'Comms - WLAN', row: 'specs.wifi'},
   { label: 'Comms - NFC', row: 'specs.nfc',},
   { label: 'Comms - DP', row: 'specs.dp',},
   { label: 'FPS', row: 'specs.fps', },
   { label: 'Sensors', row: 'specs.sensors'},
   { label: 'Power - Battery', row: 'specs.battery'},
   { label: 'Power - Charging', row: 'specs.charging'},
   { label: 'Power - Wireless', row: 'specs.wlc'},
   { label: 'Android', row: 'specs.android'},
   { label: 'TMC', row: 'TMC'},
]

const toNum = (_in) => {
   if (_in=="") return 0;
   const value = parseFloat(_in);
   return isNaN(value) ? 0 : value;
}

// 统计 specs 的总值
export const getTMCTotal = (data) => {
   const { specs = {} } = data
   let tmcTotal = 0
   editSpecsRows.forEach(row => {
      if (row.isAdd) {
         tmcTotal += toNum((specs[row.field] || {}).price)
      }
   })
   return tmcTotal.toFixed(2)
}
